package com.xb.p9_menugroup;

import android.content.Intent;
import android.os.Bundle;

import com.google.android.material.floatingactionbutton.FloatingActionButton;
import com.google.android.material.snackbar.Snackbar;

import androidx.annotation.NonNull;
import androidx.appcompat.app.AppCompatActivity;
import androidx.appcompat.widget.Toolbar;

import android.view.Menu;
import android.view.MenuItem;
import android.view.View;

public class IntentActivity extends AppCompatActivity {

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_intent);
        Toolbar toolbar = findViewById(R.id.toolbar);
        setSupportActionBar(toolbar);

        FloatingActionButton fab = findViewById(R.id.fab);
        fab.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                Snackbar.make(view, "Replace with your own action", Snackbar.LENGTH_LONG)
                        .setAction("Action", null).show();
            }
        });
    }


    //使用默认的选项optionMenu
    @Override
    public boolean onCreateOptionsMenu(Menu menu) {
        getMenuInflater().inflate(R.menu.menu_intent,menu);
        return super.onCreateOptionsMenu(menu);
    }

    //选项菜单的时间处理
    @Override
    public boolean onOptionsItemSelected(@NonNull MenuItem item) {
        Intent intent =new Intent();
        intent.setAction(Intent.ACTION_SEND);//唤醒能够发送信息的APP
        intent.setType("text/plain");
        intent.putExtra(Intent.EXTRA_SUBJECT,"暖心笑话");
        intent.putExtra(Intent.EXTRA_TEXT,"给你讲个笑话吧");
        intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);//打开新的任务
        startActivity(Intent.createChooser(intent,"把快乐分享给朋友"));

        return super.onOptionsItemSelected(item);
    }
}
